package cmd

import (
	"fmt"
	"gitee.com/itgsyang/restful-api-demo/version"
	"github.com/spf13/cobra"
	"os"
)

var vers bool
var RootCmd = &cobra.Command{
	Use:   "root",
	Short: "demo后端api服务",
	Long:  "demo后端api服务",
	RunE: func(cmd *cobra.Command, args []string) error {
		if vers {
			fmt.Println(version.FullVersion())
			return nil
		}
		return nil
	},
}

func Execute() {
	if err := RootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func init() {
	RootCmd.AddCommand(serviceCmd)
	RootCmd.PersistentFlags().BoolVar(&vers, "version", false, "v")
}
